package com.bsfcs.rag.manager.impl;

import com.bsfcs.rag.entity.Counterpart;
import com.bsfcs.rag.entity.Industry;
import com.bsfcs.rag.entity.PaymentMethod;
import com.bsfcs.rag.manager.IContractManager;
import com.bsfcs.rag.repository.ICounterpartRepository;
import com.bsfcs.rag.repository.IndustryRepository;
import com.bsfcs.rag.repository.PaymentMethodRepository;
import com.bsfcs.rag.utils.CacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContractManagerImpl implements IContractManager {

    @Autowired
    private PaymentMethodRepository paymentMethodRepository;

    @Autowired
    private IndustryRepository industryRepository;

    @Autowired
    private ICounterpartRepository counterpartRepository;

    @Override
    public void cachePaymentMethod() {
        List<PaymentMethod> all = paymentMethodRepository.findAll();
        if (all.isEmpty()) {
            return;
        }
        for (PaymentMethod paymentMethod : all) {
            CacheUtils.putPaymentMethod(paymentMethod.getId(), paymentMethod);
        }
    }

    @Override
    public void cacheIndustry() {
        List<Industry> all = industryRepository.findAll();
        if (all.isEmpty()) {
            return;
        }
        for (Industry industry : all) {
            CacheUtils.putIndustry(industry.getId(), industry);
        }
    }

    @Override
    public void cacheCounterpart() {
        List<Counterpart> all = counterpartRepository.findAll();
        if (all.isEmpty()) {
            return;
        }
        for (Counterpart counterpart : all) {
            CacheUtils.putCounterpart(counterpart.getId(), counterpart);
        }
    }
}

